home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Information
/
CSMP Digest
/
volume 3
/
csmp-digest-v3-003
< prev
next >
Wrap
Text File
|
1995-12-31
|
34KB
|
928 lines
Received-Date: Mon, 14 Mar 1994 14:36:51 +0100
From: pottier@clipper.ens.fr (Francois Pottier)
Subject: C.S.M.P. Digest, Issue 3
To: csmp-digest@ens.fr
Date: Mon, 14 Mar 94 14:36:48 MET
X-Mailer: ELM [version 2.3 PL11]
Errors-To: listman@ens.fr
Reply-To: pottier@clipper.ens.fr
X-Sequence: 4
C.S.M.P. Digest Mon, 14 Mar 94 Volume 3 : Issue 3
Today's Topics:
A4 Worlds in MPW c-c++? Is it possible?
Documented sliders?
How do I know if AppleTalk uses print port?
How to convert date to seconds *correctly*?
To Handle or not to Handle?
When to unlock?
The Comp.Sys.Mac.Programmer Digest is moderated by Francois Pottier
(pottier@clipper.ens.fr).
The digest is a collection of article threads from the internet newsgroup
comp.sys.mac.programmer. It is designed for people who read c.s.m.p. semi-
regularly and want an archive of the discussions. If you don't know what a
newsgroup is, you probably don't have access to it. Ask your systems
administrator(s) for details. If you don't have access to news, you may
still be able to post messages to the group by using a mail server like
anon.penet.fi (mail help@anon.penet.fi for more information).
Each issue of the digest contains one or more sets of articles (called
threads), with each set corresponding to a 'discussion' of a particular
subject. The articles are not edited; all articles included in this digest
are in their original posted form (as received by our news server at
nef.ens.fr). Article threads are not added to the digest until the last
article added to the thread is at least two weeks old (this is to ensure that
the thread is dead before adding it to the digest). Article threads that
consist of only one message are generally not included in the digest.
The digest is officially distributed by two means, by email and ftp.
If you want to receive the digest by mail, send email to listserv@ens.fr
with no subject and one of the following commands as body:
help Sends you a summary of commands
subscribe csmp-digest Your Name Adds you to the mailing list
signoff csmp-digest Removes you from the list
Once you have subscribed, you will automatically receive each new
issue as it is created.
The official ftp info is //ftp.dartmouth.edu/pub/csmp-digest.
Questions related to the ftp site should be directed to
scott.silver@dartmouth.edu. Currently no previous volumes of the CSMP
digest are available there.
Also, the digests are available to WAIS users as comp.sys.mac.programmer.src.
-------------------------------------------------------
>From btodorof@hmc.edu. (Brian Todoroff)
Subject: A4 Worlds in MPW c-c++? Is it possible?
Date: 26 Feb 1994 08:51:25 GMT
Organization: Harvey Mudd College, Claremont CA
Does anyone know if it is possible to do A4 worlds such as those in
Think C in MPW C. This would be very useful to me in writing some
external code modules for Photoshop. Please help if you can.
+++++++++++++++++++++++++++
>From macguru@halcyon.com. (Allan Foster)
Date: 27 Feb 1994 22:22:01 GMT
Organization: Guru Inc
In article <2kn2id$pvi@jaws.cs.hmc.edu>
btodorof@hmc.edu. (Brian Todoroff) writes:
> Does anyone know if it is possible to do A4 worlds such as those in
> Think C in MPW C. This would be very useful to me in writing some
> external code modules for Photoshop. Please help if you can.
Well, no. Not A4 worlds exactly. But it is fairly easy to use A5
worlds from stand alone code resources in MPW. For MPW C, it is very
check out technote 256 to show you how to do it.
Doing it with MPW C++ is a little more exciting. The main problem is
dealing with static constructors, and the need for a jump table. I
wrote a paper for MacHack 91 about doing this, and the code was
released public domain. I know it is up on AOL, and on CI$, and is
probv available on one of the internet acrhives as well.
Regards
Allan Foster
----------------------------------------------------------
I am responsible for what I say and do. -- Allan Foster --
---------------------------
>From hellstrm@access3.digex.net (Ben Hellstrom)
Subject: Documented sliders?
Date: 21 Feb 1994 14:44:13 -0500
Organization: Express Access Online Communications, Greenbelt, MD USA
I am trying to put a slider in a modeless dialog. I have tried swiping
the slider from the "Sound" CDEV and also from "Appmaker" (which I own).
After I load in the resource and set up the contrlRect, contrlValue, etc
the slider comes up looking OK and is updated properly. Furthermore,
when I click on it, FindWindow() returns a code of 'inThumb'. But when
I try to track it the slider thumb just sits there. TrackControl doesn't
return until I release the mouse button, but the contrlValue field is
unchanged.
Any suggestions?
Are there any *documented* slider CNTL resources around. Without
any documentation, they are hard to figure out. I searched through
Apple's IM and the TNs and didn't find anything under "slider".
Thanks for any help.
Ben Hellstrom
hellstrm@access.digex.net
+++++++++++++++++++++++++++
>From marshall@kauri.vuw.ac.nz (Stephen Marshall)
Date: 24 Feb 1994 20:54:50 GMT
Organization: Victoria University of Wellington
In article <2kb2ud$nth@access3.digex.net>, hellstrm@access3.digex.net (Ben
Hellstrom) wrote:
> Are there any *documented* slider CNTL resources around. Without
> any documentation, they are hard to figure out. I searched through
> Apple's IM and the TNs and didn't find anything under "slider".
>
> Thanks for any help.
>
> Ben Hellstrom
> hellstrm@access.digex.net
Somewhat foolishly I have posted a request for such a beast on
Alt.sources.mac (apparently a no-no). No responses yet. For such a commonly
implemented beast it seems to be quite uncommon to post code for it. If
anyone does post source or an explanation of how to use the sound cdevs
CNTL I would be greatful.
PS: is there not a slight copyright problem with using the CNTL resource
out of the Sound CDEV? I would have thought that Apples copyright would
prohibit plundering?
Stephen
--
Macintosh Consultant Marshall@kauri.vuw.ac.nz
Victoria University of Wellington
New Zealand
+++++++++++++++++++++++++++
>From egurney@vcd.hp.com (Eddy J. Gurney)
Date: Fri, 25 Feb 1994 18:23:20 GMT
Organization: Hewlett-Packard VCD
Stephen Marshall (marshall@kauri.vuw.ac.nz) wrote:
>In article <2kb2ud$nth@access3.digex.net>, hellstrm@access3.digex.net (Ben
>Hellstrom) wrote:
>
>> Are there any *documented* slider CNTL resources around. Without
>> any documentation, they are hard to figure out. I searched through
>> Apple's IM and the TNs and didn't find anything under "slider".
>Somewhat foolishly I have posted a request for such a beast on
>Alt.sources.mac (apparently a no-no). No responses yet. For such a commonly
>implemented beast it seems to be quite uncommon to post code for it. If
>anyone does post source or an explanation of how to use the sound cdevs
>CNTL I would be greatful.
There is a very nice freeware slider CDEF that is used in Jersey
Scientific's CMaster. The only reason I know it's freeware is from the
little blurb in the manual (which is at home right now). If someone
knows where this CDEF is available as a nice little package, with
documentation and maybe even (we can always hope) source, please let
us know!
If no one can find it, I'll extract the CDEF and explain how it works
(someone sent me e-mail a while ago explaining that it is pretty easy
to use, just use SetMinCtrl/SetMaxCtrl, etc.) in a short read me and
submit it to alt.sources.mac...
--
Eddy J. Gurney N8FPW Hewlett-Packard Company, Vancouver (USA!) Division
egurney@vcd.hp.com #include <standard-disclaimer.h>
"Failures are divided into two classes-- those who thought and never did,
and those who did and never thought." John Charles Salak
+++++++++++++++++++++++++++
>From hpoppe@ncar.ucar.edu (Herb Poppe)
Date: 25 Feb 1994 19:17:04 GMT
Organization: National Center for Atmospheric Research
In article <marshall-250294095436@makomako.its.vuw.ac.nz>
marshall@kauri.vuw.ac.nz (Stephen Marshall) writes:
> In article <2kb2ud$nth@access3.digex.net>, hellstrm@access3.digex.net
(Ben
> Hellstrom) wrote:
>
> > Are there any *documented* slider CNTL resources around. Without
> > any documentation, they are hard to figure out. I searched through
> > Apple's IM and the TNs and didn't find anything under "slider".
> > ...
>
> Somewhat foolishly I have posted a request for such a beast on
> Alt.sources.mac (apparently a no-no). No responses yet. For such a
commonly
> implemented beast it seems to be quite uncommon to post code for it. If
> anyone does post source or an explanation of how to use the sound cdevs
> CNTL I would be greatful.
>...
Source code (in C) for a slider CDEF (horiz. orientation only) is
available at the alt.sources.mac archive:
ftpbio.bgsu.edu
in:
"/Bio Mail Server/ftp/pub/alt.sources.mac/"
as:
cdef-slider.cpt
cdef-slider.info
Herb Poppe National Center for Atmospheric Research (NCAR)
hpoppe@ncar.ucar.edu 1850 Table Mesa Dr.
(303) 497-1296 Boulder, CO 80303
+++++++++++++++++++++++++++
>From hellstrm@access2.digex.net (Ben Hellstrom)
Date: 26 Feb 1994 14:30:41 -0500
Organization: Express Access Online Communications, Greenbelt, MD USA
In article <marshall-250294095436@makomako.its.vuw.ac.nz>,
Stephen Marshall <marshall@kauri.vuw.ac.nz> wrote:
>In article <2kb2ud$nth@access3.digex.net>, hellstrm@access3.digex.net (Ben
>Hellstrom) wrote:
>
>> Are there any *documented* slider CNTL resources around. Without
>> any documentation, they are hard to figure out. I searched through
>> Apple's IM and the TNs and didn't find anything under "slider".
>>
>> Thanks for any help.
>>
>> Ben Hellstrom
>> hellstrm@access.digex.net
>
>Somewhat foolishly I have posted a request for such a beast on
>Alt.sources.mac (apparently a no-no). No responses yet. For such a commonly
>implemented beast it seems to be quite uncommon to post code for it. If
>anyone does post source or an explanation of how to use the sound cdevs
>CNTL I would be greatful.
>
>PS: is there not a slight copyright problem with using the CNTL resource
>out of the Sound CDEV? I would have thought that Apples copyright would
>prohibit plundering?
>
>Stephen
>--
The sound CDEV is already in public domain (ftp.apple.com) with liscence
to copy. I didn't intend to distribute it. BTW, I also own AppMaker 1.5.4
which *also* has the identical slider and liscence to distribute. The
darndest thing is that I can easily put together an AppMaker project where
the slider works but when I transfer the code resources over to my project
it stops working!!
Ben Hellstrom
hellstrm@access.digex.net
---------------------------
>From johnc@flora.ruakura.cri.nz (John Curtis)
Subject: How do I know if AppleTalk uses print port?
Date: 21 Feb 1994 20:48:20 GMT
Organization: Hort+Research
How do I find out if AppleTalk is controlling the printer port?
I can check to see if the serial drivers are in use via CRMIsDriverOpen().
Likewise I can see if .MPP or .ATP is open, but can't tell if they're using
ethernet or the printer port...
Basically I want my app to ask before stealing the printer port...
Thanks!
--
-----------------------------------------------------------------------------
John Curtis |
Hort+Research | johnc@flora.ruakura.cri.nz
Hamilton, New Zealand | curtisj@ruakura.cri.nz
+++++++++++++++++++++++++++
>From Bob@lapwing.demon.co.uk (Bob Lindsey)
Date: Tue, 22 Feb 1994 05:35:50 +0000
Organization: LapWing Communications Ltd
In article <johnc-220294085249@160.4.128.121>
johnc@flora.ruakura.cri.nz "John Curtis" writes:
> How do I find out if AppleTalk is controlling the printer port?
IM vol II, pages 304 to 305 cover this.
--
Bob Lindsey on bob@lapwing.demon.co.uk
+++++++++++++++++++++++++++
>From d88-jwa@hemul.nada.kth.se (Jon Wdtte)
Date: 22 Feb 1994 17:09:22 GMT
Organization: Royal Institute of Technology, Stockholm, Sweden
In <johnc-220294085249@160.4.128.121> johnc@flora.ruakura.cri.nz (John Curtis) writes:
>How do I find out if AppleTalk is controlling the printer port?
>Basically I want my app to ask before stealing the printer port...
Just call OpenDriver on the out port; if LocalTalk is using it,
you will get a port busy error back.
Of course, you should use the Comms Resource Manager to build
a pop-up menu for the user to selects what port to use. See
code in the FAQ.
--
-- Jon W{tte, h+@nada.kth.se, Mac Hacker Deluxe --
What we need is a good GNU [...] licence manager implementation.
-- Raphael Manfredi
+++++++++++++++++++++++++++
>From leonardr@netcom.com (Leonard Rosenthol)
Date: Wed, 23 Feb 1994 18:58:51 GMT
Organization: Aladdin Systems, Inc.
In article <2kde82$836@news.kth.se>, d88-jwa@hemul.nada.kth.se (Jon Wtte)
wrote:
> In <johnc-220294085249@160.4.128.121> johnc@flora.ruakura.cri.nz (John Curtis) writes:
>
> >How do I find out if AppleTalk is controlling the printer port?
> >Basically I want my app to ask before stealing the printer port...
>
> Just call OpenDriver on the out port; if LocalTalk is using it,
> you will get a port busy error back.
>
Nope, won't work! _OpenDriver does NOT return "Port in Use" :(.
Also, the other issue that no one has yet brought up is that on certain
machines (ie. Duos) there is only ONE external serial port which doubles as
both modem & printer port. This is a very special case you need to worry
about when trying things like this.
Leonard
--------------------------------------------------------------------------
Leonard Rosenthol Internet: leonardr@netcom.com
Director of Advanced Technology AppleLink: MACgician
Aladdin Systems, Inc. GEnie: MACgician
+++++++++++++++++++++++++++
>From jvp@tools1.ee.iastate.edu (Jim Van Peursem)
Date: 24 Feb 94 21:55:42 GMT
Organization: Iowa State University, Ames, Iowa
>> In <johnc-220294085249@160.4.128.121> johnc@flora.ruakura.cri.nz (John Curtis) writes:
>>
>> >How do I find out if AppleTalk is controlling the printer port?
>> >Basically I want my app to ask before stealing the printer port...
>In article <2kde82$836@news.kth.se>, d88-jwa@hemul.nada.kth.se (Jon Wtte)
>wrote:
>> Just call OpenDriver on the out port; if LocalTalk is using it,
>> you will get a port busy error back.
In <leonardr-230294105851@leonardr.slip.netcom.com> leonardr@netcom.com (Leonard Rosenthol) writes:
> Nope, won't work! _OpenDriver does NOT return "Port in Use" :(.
It returns error -97 (portInUse) every time I do it. This may be on
the particular machines I'm testing this on, but I doubt it. Error -97
is an AppleTalk error.
This may be confused with "how do I tell if a port is open" which is
NOT possible. But if the port is using AppleTalk, it IS possible.
> Also, the other issue that no one has yet brought up is that on certain
>machines (ie. Duos) there is only ONE external serial port which doubles as
>both modem & printer port. This is a very special case you need to worry
>about when trying things like this.
Or worse yet, inconsistancies in the API between machines. Read my
message regarding the PB100 difference I recently discovered.
+---------------------------------------------------------------+
| Jim Van Peursem - Ph.D. Candidate - Ham Radio -> KE0PH |
| Department of Electrical Engineering and Computer Engineering |
| Iowa State University - Ames, IA 50011 : (515) 294-8339 |
| internet - jvp@iastate.edu -or- jvp@cpre1.ee.iastate.edu |
+---------------------------------------------------------------+
+++++++++++++++++++++++++++
>From egurney@vcd.hp.com (Eddy J. Gurney)
Date: Fri, 25 Feb 1994 18:45:24 GMT
Organization: Hewlett-Packard VCD
Jim Van Peursem (jvp@tools1.ee.iastate.edu) wrote:
>>> In <johnc-220294085249@160.4.128.121> johnc@flora.ruakura.cri.nz writes:
>>>
>>> >How do I find out if AppleTalk is controlling the printer port?
>>> >Basically I want my app to ask before stealing the printer port...
> It returns error -97 (portInUse) every time I do it. This may be on
>the particular machines I'm testing this on, but I doubt it. Error -97
>is an AppleTalk error.
> This may be confused with "how do I tell if a port is open" which is
>NOT possible. But if the port is using AppleTalk, it IS possible.
Why is it NOT possible? Can't you call GetDCtrlEntry on ports 5,6,7,8
(depending on which port you want to know is open... .Ain, .Aout, .Bin,
or .Bout, respectively) and check bit 5 of the dCtlFlags, which is set
if the driver is open?
This should work for the built-in ports; don't know how you'd do it for
Comm Toolbox drivers (since you don't know the driver's refNum... or
do you?)
--
Eddy J. Gurney N8FPW Hewlett-Packard Company, Vancouver (USA!) Division
egurney@vcd.hp.com #include <standard-disclaimer.h>
"Failures are divided into two classes-- those who thought and never did,
and those who did and never thought." John Charles Salak
+++++++++++++++++++++++++++
>From leonardr@netcom.com (Leonard Rosenthol)
Date: Fri, 25 Feb 1994 23:13:12 GMT
Organization: Aladdin Systems, Inc.
In article <CLsMro.Dn7@vcd.hp.com>, egurney@vcd.hp.com (Eddy J. Gurney)
wrote:
> Jim Van Peursem (jvp@tools1.ee.iastate.edu) wrote:
>
> > This may be confused with "how do I tell if a port is open" which is
> >NOT possible. But if the port is using AppleTalk, it IS possible.
>
> Why is it NOT possible? Can't you call GetDCtrlEntry on ports 5,6,7,8
> (depending on which port you want to know is open... .Ain, .Aout, .Bin,
> or .Bout, respectively) and check bit 5 of the dCtlFlags, which is set
> if the driver is open?
>
You can certainly do this - works like a champ and it is how most
applications today check for "port in use" since _OpenDriver is not
guaranteed to do it (see appropriate Tech Note).
> This should work for the built-in ports; don't know how you'd do it for
> Comm Toolbox drivers (since you don't know the driver's refNum... or
> do you?)
>
You can get the names of each port via the Communications Resource
Manager (CRM), and then walk through the DCE's to find the entry for the
port in question.
Leonard
--------------------------------------------------------------------------
Leonard Rosenthol Internet: leonardr@netcom.com
Director of Advanced Technology AppleLink: MACgician
Aladdin Systems, Inc. GEnie: MACgician
+++++++++++++++++++++++++++
>From jvp@tools1.ee.iastate.edu (Jim Van Peursem)
Date: 26 Feb 94 20:18:14 GMT
Organization: Iowa State University, Ames, Iowa
>> Jim Van Peursem (jvp@tools1.ee.iastate.edu) wrote:
>>
>> > This may be confused with "how do I tell if a port is open" which is
>> >NOT possible. But if the port is using AppleTalk, it IS possible.
>In article <CLsMro.Dn7@vcd.hp.com>, egurney@vcd.hp.com (Eddy J. Gurney)
>wrote:
>> Why is it NOT possible? Can't you call GetDCtrlEntry on ports 5,6,7,8
>> (depending on which port you want to know is open... .Ain, .Aout, .Bin,
>> or .Bout, respectively) and check bit 5 of the dCtlFlags, which is set
>> if the driver is open?
In <leonardr-250294151312@leonardr.slip.netcom.com> leonardr@netcom.com (Leonard Rosenthol) writes:
> You can certainly do this - works like a champ and it is how most
>applications today check for "port in use" since _OpenDriver is not
>guaranteed to do it (see appropriate Tech Note).
Ah, but is bit 5 guaranteed? From the tech note it looks like a bit of
a kludge. From the language, is sounded like it's how the CRM does it, but
it's not guaranteed.
+---------------------------------------------------------------+
| Jim Van Peursem - Ph.D. Candidate - Ham Radio -> KE0PH |
| Department of Electrical Engineering and Computer Engineering |
| Iowa State University - Ames, IA 50011 : (515) 294-8339 |
| internet - jvp@iastate.edu -or- jvp@cpre1.ee.iastate.edu |
+---------------------------------------------------------------+
---------------------------
>From cbo@cs.toronto.edu (Calvin Bruce Ostrum)
Subject: How to convert date to seconds *correctly*?
Date: 24 Feb 94 19:56:23 GMT
Organization: Department of Computer Science, University of Toronto
This may strike people as an ignorant and trivial question, but I need
to know the answer anyway. How does one convert a date (y/m/d h:m:s) to
seconds elapsed since Jan 1 1904? I don't have very complete documentation
for the tools I have available, and in MPW 3.2 am using mktime. This seems
to pick up the local time zone okay, but it does not seem to pick up whether
daylight savings time is active. This is what I need it to do. When I read
in a file of dates without timezone specified, it should use the local time
zone, which it does. But it should also subtract an hour from the date
before doing the conversion if the date is during the time of year when
daylight savings time is active. This it does not do. Is there something
I can set to make it do this? (If not, is there a simple uniform rule that
determines when dst stops and starts? I suppose I should have picked this
rule up by now, but I haven't).
Please email responses. Thank you.
---------------------------------------------------------------------------
Calvin Ostrum cbo@cs.toronto.edu
---------------------------------------------------------------------------
It is a far, far better thing to have a firm anchor in nonsense than
to put out on the troubled seas of thought. -- John Kenneth Galbraith
---------------------------------------------------------------------------
+++++++++++++++++++++++++++
>From resnick@cogsci.uiuc.edu (Pete Resnick)
Date: Sun, 27 Feb 1994 13:10:02 -0600
Organization: University of Illinois at Urbana-Champaign
In article <94Feb24.145607est.48169@neat.cs.toronto.edu>,
cbo@cs.toronto.edu (Calvin Bruce Ostrum) wrote:
>This may strike people as an ignorant and trivial question, but I need
>to know the answer anyway. How does one convert a date (y/m/d h:m:s) to
>seconds elapsed since Jan 1 1904?
The system routines String2Date and String2Time will convert string
representations into a date record. These will work for all kinds of
international representations and other variations on the standard by
using the system tokenizer. The date record can be converted to number of
seconds since 1/1/1904 by using LongDate2Secs.
>This seems to pick up the local time zone okay, but it does not seem to pick
>up whether daylight savings time is active. This is what I need it to do. When
>I read in a file of dates without timezone specified, it should use the local
>time zone, which it does. But it should also subtract an hour from the date
>before doing the conversion if the date is during the time of year when
>daylight savings time is active. This it does not do. Is there something I can
>set to make it do this? (If not, is there a simple uniform rule that
>determines when dst stops and starts? I suppose I should have picked this rule
>up by now, but I haven't).
The rules for daylight savings time not only vary from country to country,
but they also vary within countries. (Arizona and parts of Indiana do not
use daylight savings). The only way to account for it is to have the time
zone encoded in the date string itself, either using rules which tell you
whether daylight savings is in effect, like using "CST" for Central
Standard Time and "CDT" for Central Daylight Time, or using an absolute
offset from GMT, like "-0600" for Central Standard Time (6 hours less than
GMT) or "-0500" for Central Daylight Time (5 hours less than GMT).
I am working on a routine that uses all of the international routines
properly to encode and decode such strings according to RFC 822 and RFC
1123 rules, including parsing out comments. I will post it to the net when
I am finished.
pr
--
Pete Resnick (...so what is a mojo, and why would one be rising?)
Graduate assistant - Philosophy Department, Gregory Hall, UIUC
System manager - Cognitive Science Group, Beckman Institute, UIUC
Internet: resnick@cogsci.uiuc.edu
---------------------------
>From francis@pinza.demon.co.uk (Francis H. Knight)
Subject: To Handle or not to Handle?
Date: Fri, 25 Feb 1994 19:33:16 GMT
Organization: Hertfordshire Mac Oasis
Recently finding myself with an unanticipated amount of free time, I'm
using
the opportunity to get up to speed with Think C (5.0.4).
I've got myself a deeply nested struct, which contains a load of
configuration stuff, etcetera, and I've referred to this struct by a
Handle,
so the memory manager those kind folks at Apple gave us can do its stuff.
Now, a lot of the general-purpose lower-level functions operate on
components
of the struct, so I'm dereferencing them before entering the functions.
I'm finding it very laborious, and not very creative, to work out where to
bracket (de-)references to the struct with HLock/HUnlock, given that a heap
compaction trigger may be hidden within several layers of function calls.
In
fact, I'm sure I've missed some, as I'm still experiencing Bus Errors.
To help my thinking, can anyone offer any good:
Methods of deciding where to HLock/HUnlock? I'm using the manual method
of combing through my code line by line and checking against the list
of memory-moving routines in Inside Mac. I feel my Mac ought to be able
to flag the potential triggers for me!
Criteria for judging at the outset of a project whether the hassle
of correct HLock/HUnlocking is going to outweigh the benefits of using
NewHandle over NewPtr?
Methods for debugging CDEVs under System 7? Or is this problem a good
reason to create the interface as a small Application, in this age
of MultiFinder and AppleEvents?
Cheers and thanks,
Francis K.
At a Mac Oasis Somewhere in Suburban Hertfordshire
+++++++++++++++++++++++++++
>From jwbaxter@olympus.net (John W. Baxter)
Date: Fri, 25 Feb 1994 15:04:07 -0800
Organization: Internet for the Olympic Peninsula
In article <francis-250294193316@pinza.demon.co.uk>,
francis@pinza.demon.co.uk (Francis H. Knight) wrote:
> I'm finding it very laborious, and not very creative, to work out where to
> bracket (de-)references to the struct with HLock/HUnlock, given that a heap
> compaction trigger may be hidden within several layers of function calls.
> In
> fact, I'm sure I've missed some, as I'm still experiencing Bus Errors.
>
> To help my thinking, can anyone offer any good:
>
> Methods of deciding where to HLock/HUnlock? I'm using the manual method
> of combing through my code line by line and checking against the list
> of memory-moving routines in Inside Mac. I feel my Mac ought to be able
> to flag the potential triggers for me!
Any function call may move memory (by loading a segment), unless you *KNOW*
that every segment which might be called by the function you call is
already loaded, and that the function you call will never be modified to
change what you once knew. IMHO: assume a function call moves memory.
Someone may "improve" the code next week. And of course: "that little
change couldn't hurt anything, we don't need to retest before the
deadline."
Even those traps listed as not moving memory may (someday, if not now).
SysBeep is a classic example; it didn't...it often does now.
Any trap may have been patched. The patch should behave, with respect to
moving memory, no "worse" than the version in ROM (any ROM, by the way).
But...both shareware and commercial ware messes this up, too. IMHO: treat
any trap as moving memory.
> Criteria for judging at the outset of a project whether the hassle
> of correct HLock/HUnlocking is going to outweigh the benefits of using
> NewHandle over NewPtr?
Years of experience combined with lucky guesses.
> Methods for debugging CDEVs under System 7? Or is this problem a good
> reason to create the interface as a small Application, in this age
> of MultiFinder and AppleEvents?
There's not much reason for writing Control Panels any more, if you only
support System 7 and later. If you never write one, you never have to
learn how.
--
John Baxter Port Ludlow, WA, USA [West shore, Puget Sound]
jwbaxter@pt.olympus.net
+++++++++++++++++++++++++++
>From AIKEN <INRA000@MUSICB.MCGILL.CA>
Date: Sat, 26 Feb 1994 01:13:20 GMT
Organization: McGill University
In article <jwbaxter-250294150408@ptpm006.olympus.net> jwbaxter@olympus.net (John W. Baxter) writes:
>In article <francis-250294193316@pinza.demon.co.uk>,
>francis@pinza.demon.co.uk (Francis H. Knight) wrote:
>> Methods for debugging CDEVs under System 7? Or is this problem a good
>> reason to create the interface as a small Application, in this age
>> of MultiFinder and AppleEvents?
>
>There's not much reason for writing Control Panels any more, if you only
>support System 7 and later. If you never write one, you never have to
>learn how.
A quick note on this: I still feel constrained to write a Control
Panel if I have nothing to put in the Menu Bar of a possible replacement
application. Control Panels still have the advantage of being window-
only and opening in the Finder's layer. If Apple seriously wanted to
junk the whole Control Panel interface, I would love to see a new type
of application: 'mbla' -- menu bar-less app. To open with a face but
without a menu bar. Or will this go away when Apple kills off
application layers alltogether? :-)
Mark Aiken
inra@musicb.mcgill.ca
+++++++++++++++++++++++++++
>From aep@world.std.com (Andrew E Page)
Date: Sat, 26 Feb 1994 15:08:18 GMT
Organization: The World Public Access UNIX, Brookline, MA
Way back when, when I was learing to program a mac(do no ask) I
think the best peice of advice I picked up from a technote or a
BBS(can't remember where), was that when handles are concerned:
IT PAYS TO BE PARANOID. ALWAYS LOCK THEM BEFORE USING THEM.
When you're using your own data structs in handles sometimes it
becomes a royal pain to be always typing:
HLock((Handle)MyHandle) ;
HUnlock((Handle)MyHandle) ;
So I created the folowing macros in my personal 'types' file:
#define HLOCK(h) HLock((Handle)h)
#define HLOCKHI(h) HLockHi((Handle)h)
#define HUNLOCK(h) HUnlock((Handle)h)
Save's alot of extra typing, improves the readability of the code.
Always check MemError() afterwards though, Admittedly, it can get
cumbersome, but it's better than spending a couple days of debugging
just to find out you passed a function a bogus handle at some point.
foo()
{
MyStruct **MyHnd, *MyPtr ;
OSErr err ;
HLOCK(MyHnd) ;
if( err = MemError() )
HandleMemError(err) ;
MyPtr = *MyHnd ;
MyPtr->someData = X ;
/*
* other arcane and silly operations.
*/
HUNLOCK(MyHnd) ;
}
Lately though I've been using the calls HGetState and HSetState
more frequently, to guarantee that I'm not going to unlock something
that had been locked somewhere else before. (That's an ouch)
#define HGETSTATE(h) HGetState(h)
#define HSETSTATE(h, c) HSetState(h, c)
foo(MyStruct **MyHnd)
{
MyStruct *MyPtr ;
OSErr err ;
char hndState ;
hndState = HGETSTATE(MyHnd) ;
HLOCK(MyHnd) ;
if( err = MemError() )
HandleMemError(err) ;
MyPtr = *MyHnd ;
MyPtr->someData = X ;
/*
* other arcane and silly operations.
*/
HSETSTATE(MyHnd, hndState) ;
}
By doing this religiously you can save yourself MUCH trouble
throughout a programming project where you're passing back and forth
alot of data in handles.
--
Andrew E. Page (Warrior Poet) | Decision and Effort The Archer and Arrow
Mac Consultant | The difference between what we are
Macintosh and DSP Technology | and what we want to be.
---------------------------
>From gurgle@netcom.com (Pete Gontier)
Subject: When to unlock?
Date: Sat, 26 Feb 1994 22:25:50 GMT
Organization: cellular
Submitted-by: gurgle@netcom.com
Archive-name: oHandleLocker.cp
francis@pinza.demon.co.uk (Francis H. Knight) writes:
>I'm finding it very laborious, and not very creative, to work out where
>to bracket (de-)references to the struct with HLock/HUnlock, given
>that a heap compaction trigger may be hidden within several layers
>of function calls.
Essential Secret of Macintosh Programming #412
----------------------------------------------
Never call HUnlock.
Instead, do this:
OSErr WhackHandle (Handle foo)
{
OSErr oe = noErr;
char hState = HGetState (foo);
if (!(oe = MemError ( )))
{
HLock (foo);
if (!(oe = MemError ( )))
{
// whack the handle
HSetState (foo,hState);
if (!oe) oe = MemError ( );
}
}
return oe;
}
The above is laborious, but that's what C++ is for:
class oHandleLocker
{
char fState;
Handle fHandle;
public :
oHandleLocker (Handle h)
{ fState = HGetState (h); HLock (h); fHandle = h; }
~oHandleLocker (void) // not virtual deliberately
{ HSetState (fHandle, fState); }
}
void WhackHandle (Handle h)
{
oHandleLocker locked (h);
// whack the handle;
// it will automagically be unlocked at function exit
}
Note that the C++ version omits calls to MemError; that's the price you
pay for a C++ compiler without exceptions. Most people don't bother with
MemError when calling HLock/HGetState/HSetState anyway. I do, but that's
neither here nor there. Just be aware of it.
Also, oHandleLocker might benefit (depending on your world-view) from
dealing with 'void *' instead of 'Handle'. I've used Handle here in
order to avoid explaining why 'void *' might be useful.
(By the way, none of the enclosed code has been compiled, but it should
only require minimal changes, and the principles are sound; I have used
them before.)
--
Pete Gontier, CTO, Integer Poet Software; gurgle@netcom.com
---------------------------
End of C.S.M.P. Digest
**********************